package com.bblocks.standard.controller;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.bblocks.enums.AppTypeEnum;
import com.bblocks.standard.vo.GlobalVo;
import com.bblocks.standard.vo.InParamsVo;
import com.bblocks.standard.vo.OutParamsVo;
import com.bblocks.util.R;
import com.google.common.collect.Lists;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.pig.common.swagger.annotation.ApiGlobalModel;
import com.pig4cloud.pig.common.swagger.annotation.ApiIgn;
import com.pig4cloud.pig.common.swagger.annotation.ApiInclude;
import com.pig4cloud.pig.common.swagger.annotation.ApiJsonModel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>Project: bblocks-pro - TestController</p>
 * <p>描述：swagger 插件测试
 * 优化快速生成文档
 * </p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/2/28 14:48
 * @Version 1.0
 * @since 8
 */
@Slf4j
@Tag(description = "TestSwaggerPlugins", name = "测试swagger文档生成")
@RestController
@RequestMapping("/testSwagger")
public class TestSwaggerPluginsController {

    @Operation(summary = "测试忽略入参", description = "测试忽略入参控制")
    @PostMapping("/paramsIgn")
    public R<OutParamsVo> paramsIgn(@ApiIgn(value={"id,appType"},annotation = {"name@姓名"}) @RequestBody  InParamsVo params) {
        return getDefault();
    }

    @Operation(summary = "测试仅输出入参", description = "测试仅输出入参控制")
    @PostMapping("/paramsInclude")
    public R<OutParamsVo> paramsInclude(@ApiInclude(value={"id,appType"},annotation = {"appType@app类型"}) @RequestBody  InParamsVo params) {
        return getDefault();
    }

    @PostMapping("/testCommParams")
    @Operation(summary = "测试通用入参控制", description = "测试通用入参控制-只显示要求输入")
    @ApiGlobalModel(component = GlobalVo.class, value = "code,aliCode,otherType")
    public R<OutParamsVo> testCommParams(@RequestBody JSONObject param) {
        //***************************** 读取参数并校验 *******************************/
        String id = param.getString("skuId");
        String code = param.getString("code");
        Integer otherType = param.getInteger("otherType");
        //***************************** 处理业务并返回 *******************************/
        return R.ok();
    }

    @ApiJsonModel({
            @Schema(name = "skuId", description = "sku_id"),
            @Schema(name = "code", description = "支付宝code"),
            @Schema(name="otherType",description = "其他类型",type = "integer")
     })
    @PostMapping("/testJsonParams")
    @Operation(summary = "测试json入参控制", description = "测试json入参控制-")
    public R<OutParamsVo> testJsonParams(@RequestBody JSONObject param) {
        //***************************** 读取参数并校验 *******************************/
        String id = param.getString("skuId");
        String code = param.getString("code");
        Integer otherType = param.getInteger("otherType");
        //***************************** 处理业务并返回 *******************************/
        return R.ok();
    }









    private R<OutParamsVo> getDefault(){
        int total = 50;
        List<OutParamsVo> out2Inners = Lists.newArrayListWithExpectedSize(total);
        OutParamsVo one =  OutParamsVo
                .builder()
                .appType(AppTypeEnum.Upms)
                .id("id2子1")
                .name("赵2子1")
                .time(LocalDateTime.now())
                .indexNo(2)
                .build();

        out2Inners.add(one);
        for(int i = 1;i<total;i++){
            OutParamsVo newOne = BeanUtil.toBean(one,OutParamsVo.class);
            newOne .setIndexNo(i + 2);
            out2Inners.add(newOne);
        }

        return R.ok(OutParamsVo
                .builder()
                .indexNo(0)
                .appType(AppTypeEnum.App)
                .id("id1")
                .name("赵")
                .time(LocalDateTime.now())
                .outInner(
                        OutParamsVo
                                .builder()
                                .indexNo(1)
                                .appType(AppTypeEnum.Upms)
                                .id("id1子")
                                .name("赵子")
                                .time(LocalDateTime.now())
                                .build()
                )
                .out2Inners(out2Inners)
                .build()) ;
    }

}
